/*
package cn.ym.mall.listener;

import cn.cyh.news.entity.Topic;
import cn.cyh.news.service.TopicService;
import cn.cyh.news.service.impl.TopicServiceImpl;

import javax.servlet.*;
import javax.servlet.annotation.WebListener;
import java.util.List;

@WebListener
public class ApplicationListener implements ServletContextListener, ServletContextAttributeListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("上下文被创建");
        ServletContext application = sce.getServletContext();
        try {
            // 加载新闻主题
            TopicService topicService = new TopicServiceImpl();
            List<Topic> topicList = topicService.getAllTopic();
            application.setAttribute("topicList", topicList);
            System.out.println("新闻主题加载成功：" + topicList.size());
        } catch (Exception e) {
            System.out.println("新闻主题加载失败");
            e.printStackTrace();
        }
        // 加载系统参数
        try {
            application.setAttribute("appName","新闻中国");
            System.out.println("appName加载成功");
        } catch (Exception e) {
            System.out.println("appName加载失败");
            e.printStackTrace();
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("上下文被销毁");
    }

    @Override
    public void attributeAdded(ServletContextAttributeEvent scae) {
        System.out.println("上下文添加：" + scae.getName() + "=" + scae.getValue());
    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent scae) {
        System.out.println("上下文删除：" + scae.getName() + "=" + scae.getValue());
    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent scae) {
        System.out.println("上下文替换：" + scae.getName() + "=" + scae.getValue());
    }
}
*/
